/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
 var searchRange = function(nums, target) {
  const getLeft = function(nums,target){
    let left = 0
    let right = nums.length - 1
    let leftBridge = -2
    while(left <= right){
      let mid = left + Math.floor((right - left) / 2)
      if(nums[mid] >= target){
        right = mid - 1
        leftBridge = right
      }else {
        left = mid + 1
      }
    }
    return leftBridge
  }
  const getRight = function(nums,target){
    let left = 0
    let right = nums.length - 1
    let rightBedge = -2
    while(left <= right){
      let mid = left + Math.floor((right - left) / 2)
      if(nums[mid] > target){
        right = mid - 1
      }else {
        left = mid + 1
        rightBedge = left
      }
    }
    return rightBedge
  }
  let leftBridge = getLeft(nums,target)
  let rightBedge = getRight(nums,target)
  if(leftBridge === -2 || rightBedge === -2) return [-1,-1]
  if(rightBedge - leftBridge > 1) return [leftBridge + 1,rightBedge - 1]
  return [-1,-1]
};